/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager.search;

import br.com.foxline.manager.edit.ManagerEditCustomer;
import br.com.foxline.model.Address;
import br.com.foxline.model.Customer;
import br.com.foxline.service.CustomerService;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerViewCustomer implements Serializable{
    
     
    @EJB
    CustomerService customerService;
    
    private Customer customer;
    
    private List<Address> addresses;
    
    private Customer conjugue;

   
    
     public void pageViewCustomer(String s, Customer c) {
        this.customer = customerService.find(c.getId());
        this.addresses = customerService.findAddresses(this.customer);
        this.conjugue  = this.customer.getSpouse();
        redirect(s, c);
    }

    public void redirect(String string, Object o) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerViewCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public Customer getConjugue() {
        return conjugue;
    }

    public void setConjugue(Customer conjugue) {
        this.conjugue = conjugue;
    }
    

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public List<Address> getAddresses() {
        return addresses;
    }

    public void setAddresses(List<Address> addresses) {
        this.addresses = addresses;
    }
    
    
    
    
}
